home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
libs
/
knowhow4
/
graf.txt
< prev
next >
Wrap
Text File
|
1994-11-08
|
7KB
|
183 lines
/*
█████████████████████████████████████████████████████████████████████████████
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ KNOW-HOW.GRAF ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
█████████████████████████████████████████████████████████████████████████████
This text contain complete description of KNOW_HOW.GRAF 5.0x, the
product in the 5th version of library. It provide the following features:
a) Graphics and diagrams of different types.
b) The same in Window, if KNOW-HOW.Interface is used.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ FILES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
▐▐▐▐▐▐▐ Files AXE.H and AXE.CPP incapsulate attributes of AXE: length and
so on. If you want not use automatic calculation of ticks coordinates,
use start == end in the call to calc_labels() function and pass to it
array of ticks coordinates.
▐▐▐▐▐▐▐ Files H_V_AXES.H and H_V_AXES.CPP define two axes: X and Y. Two
additional axes (second X and second Y) are available too:
enum axes_dir { HORIZ_AXE, VERT_AXE };
enum axes_type { NORMAL_AXE, REVERSE_AXE };
class HV_Axes : public Axe
{
public:
int type; // Type of axe
int dir; // Direction of axe
int text_dir; // Direction of the text lof labels
public:
HV_Axes(int l, double start = 0, double end = 0,
int tick_no = 5, int* t = NULL,
int s_tick_no = 0, int* s = NULL,
char** lab = NULL);
virtual void show_labels(loc);
void set_type(int t, int d, int td = HORIZ_DIR);
virtual loc get_label_pos(loc, int );
virtual void show_axe(loc, int);
};
▐▐▐▐▐▐▐ Files AXES.H and AXES2.CPP contains code for Axes2 class. This class
operate with two pares of axes : X1-Y1 and X2-Y2.
enum { HORIZ1, VERT1, HORIZ2, VERT2 };
class Axes2
{
protected:
HV_Axes* horiz_axe;
HV_Axes* vert_axe;
HV_Axes* horiz_axe_2;
HV_Axes* vert_axe_2;
public:
Axes2();
~Axes2()
{ delete horiz_axe; delete vert_axe;
delete horiz_axe_2; delete vert_axe_2; }
void cross(rect coord, loc zero); // Draw beginning of the coord.
void set_axe(int which_axe, int axe_len,
double start = 0, double end = 0,
int tick_no = 0, int* ticks_on_axe = NULL,
int s_tick_no = 0, int* sub_ticks_on_axe = NULL,
char** legends_on_axe = NULL, int text_direction = HORIZ_DIR);
void show(loc left_top_of_axe, int ax_color, int legends_color);
};
▐▐▐▐▐▐▐ Files MARKER.H and MARKER.CPP. Marker is the geometric figure for
drawing data (point) on the graphs.
enum { NONE, BAR, CIRCLE, TRIANGLE, STAR5, STAR6, CROSS, X_CROSS,
DIAMOND, TRIANGLE2, BAR2, CIRCLE2 };
extern void show_marker(int type, loc pos, int color, int size = 4);
▐▐▐▐▐▐▐ Files GRAF.H and GRAF.CPP. Contains class for drawing X-Y dependences
on screen.
There are few types of graphics. Line graf could be used for drawing
splines (no markers). Marker graf looks nice for the set of few (up
to 20 - 40) points. Combined graf is the combination of line and
marker grafs (data with spline). Bar and 3 dimensional bar presents
data as bars drawn from 0(Y) to y(Y). Stacked bar graf draws 3-d bars
not from zero, but from the top of previous bar.
enum { NO_GRAF, LINE_GRAF, MARKER_GRAF, COMBINED_GRAF, BAR_GRAF,
BAR_3D_GRAF, STACKED_BAR_GRAF };
struct Graf
{
int marker_type;
int line_type;
int attr; // Color
int bak; // Background
int size; // Size of marker
int fill; // Fill pattern for bar graf family. In 1.x
// version we use BGI - not VBGI graphics.
Graf(int m, int l, int a, int b, int s, int f)
{ marker_type = m; line_type = l; attr = a; bak = b; size = s;
fill = f; }
void set_type(int m, int l, int a, int b, int s, int f)
{ marker_type = m; line_type = l; attr = a; bak = b; size = s;
fill = f; }
// X and Y contains integer (screen) coordinates, which was recalculated
// from double data. Data are ordered on X axe.
void show(int* x, int* y, int number_of_points,
int x_left_of_graf, int y_left_of_graf, int num_in_container = 0);
void set_type(int m_t, int l_t)
{ line_type = l_t; marker_type = m_t; }
void set_param(int a, int b, int s, int f)
{ attr = a; bak = b; size = s; fill = f; }
};
▐▐▐▐▐▐▐ Files GRAFIC.H and GRAFIC.CPP contains code for data incapsulation
and for axes with data. Class for drawing of axes and data sets (up
to 15).
This structure incapsulate dataset with its screen attributes.
It also could be saved to disk and loaded back to memory
when necessary (this option is not automatic, and only data are
saved, not attributes, as colors and so on).
struct GrafData
{
Graf* graf; // marker_type; line_type; attr; bak; size; fill;
int* data_x; // Array of X coordinates
int* data_y; // Array of Y coordinates
int num_points; // Total number of data X-Y pares
char* fileName; // Name of file to swap data
GrafData(char attr_color, char back_color, int marker_type,
int line_type, int size_of_marker, int fill_style,
int* data_x, int* data_y, int num_points, char* fName = "");
~GrafData();
void load();
void save();
};
Class Grafic draws axes, grid and curves. It could load double
arrays and keep them as recalculated int arrays (in GrafData
structures).
class Grafic : public Axes2
{
protected:
int used; // Number of lines, 1 - 15
rect coord; // Rectangle, including labels
rect work_coord; // Rectangle, not including labels
int ax_col; int lab_col; // Axes and labels colors
loc zero;
double zero_x;
double zero_y;
double len_x;
double len_y;
int grid_style;
public:
GrafData* arrays[15];
Grafic(rect r, int ax, int lab, int g = 5, int save = 0);
~Grafic();
rect get_work_coord() { return work_coord; }
loc get_colors() { return loc(ax_col, lab_col); }
void grid();
loc get_zero(double xmin, double ymin, double xmax, double ymax);
int bar_width();
void get_x_array(int ar, int num, double* data);
void get_y_array(int ar, int num, double* data);
rect set_work_rect(rect r) { return work_coord = r; }
void set_rect(rect r) { coord = r; }
void redraw();
void show_axes();
int* get_stacked(int n);
};
▐▐▐▐▐▐▐ Files KH_GRAF.H and KH_GRAF.CPP combine KNOW-HOW.INTERFACE Window
class with graphic tools described above.